<?php
namespace Tyrone\Model;
use Medoo\Medoo;

class PayCallback extends Base
{
    protected $table = 'l_pay_callback';
    const STATUS_SUCCESS = 2;
    public function updateCallbackStatus($id, $status)
    {

        return $this->database->update($this->table,[
            'status' => $status,
            'send_num' => Medoo::raw('send_num + 1'),
        ],compact('id'));
    }

    public function singleResult($pay,$result){
        $resArr = json_decode($result,true);
        $this->updateCallbackStatus($pay['id'],$resArr["ret"] ?? -1);
        if ($resArr["ret"] == self::STATUS_SUCCESS){
            $OrderModel = new Order();
            $OrderModel->updateOrderStatus($pay["cp_order_id"], 1);
        }


    }

    public function payLog($master_platform,$pay,$playerInfo){
        //更新玩家充值金额
        $payToal = $this->database->update('l_player_pay_total',[
            'rmb' => Medoo::raw('rmb + '.$pay['rmb']),
        ],[
            'platform' => $pay["platform"],
            'plat_server' => $pay["plat_server"],
            'player_id' => $pay["player_id"],
        ]);
        $data = [
            "order_id" => $pay["order_id"],
            "cp_order_id" => $pay["cp_order_id"],
            "player_id" => $pay["player_id"],
            "username" => $pay["username"],
            "platform" => $pay["platform"],
            "plat_server" => $pay["server_id"],
            "server_id" => $pay["server_id"],
            "rmb" => $pay['rmb'],
            "charge_type" => $pay["charge_type"],
            "sub_type" => $pay["sub_type"],
            // "single_id"=>$pay["server_id"],
            "gold" => 0,
            "now_level" => $playerInfo["level"],
            "pay_date" => date("Ymd"),
            "pay_time" => time(),
            "pay_month" => date("Ym"),
            "master_platform" => $master_platform,

        ];
        $this->database->insert(OLD_CENTER_DB.'.l_player_pay',$data);
        return [$payToal->rowCount(),$this->database->id()];
    }


}